import json

filename = 'favorite_number.txt'

number = input('\nPlease input your favorite number:')

with open(filename, 'w') as f:
    json.dump(number, f)

try:
    with open(filename) as f:
        stored_number = json.load(f)
except FileNotFoundError:
    pass
else:
    print(f"I know your favorite number! It's: {stored_number}.")